package com.chixing.day10_hashcode_exception;

/**
 * 加密工具类，提供了加密解密算法
 */
public class EncryptUtil {
//加密
    public static String encrypt(String src){

        src = src.substring(1, src.length()) + src.substring(0, 1);

        char[] arr = src.toCharArray();
        int index = 0;
        for (int i = 0; i < src.length(); i++) {
            arr[index++] = (char) (src.codePointAt(i) + 3);
        }

        return  new String(arr);
    }
//解密
    public static String decrypt(String src) {
        src = src.substring(src.length() - 1) + src.substring(0, src.length() - 1);
        char[] arr = src.toCharArray();
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            arr[index++] = (char) (src.codePointAt(i) - 3);
        }
        return new String(arr);
    }


    public static void main(String[] args) {
        System.out.println( encrypt("XYZ"));
        System.out.println( decrypt("\\]["));

        String word = "1Ct3r4ip_ti4C6k9Et^";
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < word.length(); i++) {
            if (!(word.charAt(i) >= '0' && word.charAt(i) <= '9') ){
                builder.append(word.charAt(i));
            }
        }
        System.out.println(builder);
    }

}
